package com.qfjy.controller;

import org.junit.jupiter.api.Test;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;

/**
 * @author :hucaiyuan
 * @date :2022/04/09   11:35
 * @description :Lambda表达式测试
 */
public class LamdbaTest {
    @Test
    public void Test1(){
        Runnable r1=new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱北京天安门!");
            }
        };
        r1.run();
        System.out.println("********************");
        Runnable r2=() ->System.out.println("我爱北京故宫!");
        r2.run();
    }


    @Test
    public void Test2(){
        Comparator<Integer> com1=new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        int compare = com1.compare(32, 21);
        System.out.println(compare);
        System.out.println("**************************");

        Comparator<Integer> com2=(o1,  o2) ->  Integer.compare(o1, o2);
        int compare2 = com1.compare(12, 21);
        System.out.println(compare);
    }
}
